<?php
#####################################
# * @Author: lehieu008              #
# * @Email: lehieu008@gmail.com     #
# * @Copyright: 2008 - 2010         #
#####################################
if(!defined('BASEPATH'))exit('No direct script access allowed');
class Shop_module extends Controller
{
    function __construct()
    {
        parent::Controller();
    }
    
    function bestshop($home = true)
    {
        if($home == true)
        {
            $limit = 7;
            $sql = "SELECT shoLink, shoName, shoDescr, shoLogo, shoDirLogo, useYahoo, useSkype, useEmail, usePhone, useFullname, useAddress FROM {PRE}shop ";
            $sql .= "INNER JOIN {PRE}user ON {PRE}shop.shoUser = {PRE}user.useID ";
        }
        else
        {
            $limit = 12;
            $sql = "SELECT shoLink, shoName, shoDescr, shoLogo, shoDirLogo, shoLevel FROM {PRE}shop ";
        }
        $sql .= "WHERE shoStatus = 1 AND shoBestShop >= ".time()." ";
        $sql .= "ORDER BY RAND() LIMIT 0,$limit";
        $data['rows'] = $this->global_model->fetch($sql);
        $data['home'] = $home;
        #Load View
        $this->load->view('shop/bestshop', $data);
    }
    
    function saleoff()
    {
        $sql = "SELECT shoLink, shoName, shoDescr, shoLogo, shoDirLogo, useID, useYahoo, useSkype, useEmail, usePhone, useFullname, useAddress, useRegisterDate, preName FROM {PRE}shop ";
        $sql .= "INNER JOIN {PRE}user ON {PRE}shop.shoUser = {PRE}user.useID ";
        $sql .= "INNER JOIN {PRE}province ON {PRE}user.useProvince = {PRE}province.preID ";
        $sql .= "WHERE shoSaleOff = 1 AND shoStatus = 1 ";
        $sql .= "ORDER BY RAND() LIMIT 0,".SHOP_MODULE_ROWS;
        $data['rows'] = $this->global_model->fetch($sql);
        #Load View
        $this->load->view('shop/saleoff', $data);
    }
    
    function popular()
    {
        $sql = "SELECT shoLink, shoName, shoDescr, shoLogo, shoDirLogo, shoLevel, useRegisterDate, preName FROM {PRE}shop ";
        $sql .= "INNER JOIN {PRE}user ON {PRE}shop.shoUser = {PRE}user.useID ";
        $sql .= "INNER JOIN {PRE}province ON {PRE}user.useProvince = {PRE}province.preID ";
        $sql .= "WHERE shoStatus = 1 ";
        $sql .= "ORDER BY shoBestShop DESC, shoView DESC LIMIT 0,".SHOP_MODULE_ROWS;
        $data['rows'] = $this->global_model->fetch($sql);
        #Load View
        $this->load->view('shop/popular', $data);
    }
}